import App from './App.vue'
import { createApp } from 'vue'
//三级联动组件---全局组件
import MainHome from '@/components/TypeNav/MainHome.vue';
import PagesIndex from '@/components/Pagination/PagesIndex.vue';

import router from './router'
import store from './store/store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import '@/mock/index.js'
import mitt from 'mitt'; // 导入 mitt
// import { mock } from './mock/index.js';

const app = createApp(App)
// 创建事件总线
const eventBus = mitt();
app.config.globalProperties.$bus = eventBus;


app.use(router)
app.use(store)
app.use(ElementPlus)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
 
//全局组件注册
//第一个参数是组件的名字，第二个参数是组件的对象
app.component('MainHome', MainHome);
app.component('PagesIndex', PagesIndex);
app.mount('#app')

// createApp(App).mount('#app')




// 防抖函数
const debounce = (fn, delay) => {
  let timer
   return (...args) => {
     if (timer) {
       clearTimeout(timer)
     }
     timer = setTimeout(() => {
       fn(...args)
     }, delay)
   }
}
  // 重写ResizeObserver
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
   constructor(callback) {
     callback = debounce(callback, 200);
     super(callback);
   }
}
